package example.lec03.condition.dao;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration;

import example.lec03.condition.connection.MyConnection;
import example.lec03.condition.connection.MyConnectionCondition;
@Configuration
public class MyDao {
    //private String connection="success";
    private MyConnection myConnection;    
    @Bean(name="myConnection")
    public MyConnection myConnection() {
        return new MyConnection();
    }    
    @Bean(name="dao")
    @Conditional(MyConnectionCondition.class)
    public MyDao getBean() {
        MyDao dao=new MyDao();
        dao.setMyConnection(myConnection);
        return dao;
    }

    public void insert() {
        myConnection().getConnection();
        System.out.println("可以向数据库进行插入。");
    }

    public MyConnection getMyConnection() {
        return myConnection;
    }

    public void setMyConnection(MyConnection myConnection) {
        this.myConnection = myConnection;
    }
}
